<template>
  <div>
    <van-search
      v-model="value"
      shape="round"
      background="#fff"
      placeholder="请输入搜索关键词"
      @click="showPopup"
    />
    <div class="fenl">
      <van-sidebar v-model="activeKey">
        <van-sidebar-item
          v-for="item in channelList"
          :key="item.id"
          :title="item.name"
          @click="fenlFn(item.name)"
        />
      </van-sidebar>
      <!-- 右边渲染 -->
      <ul class="demo">
        <div
          v-for="items in channelList"
          :key="items.id"
          v-show="items.name == sole"
        >
          <!--   {{items.name+"------------------"+sole}} -->
          <img v-lazy="items.banner_url" height="140px" width="95%" />
          <h5>{{ items.front_desc }}</h5>
        </div>

        <!-- 居家分类 -->
        <div class="mytitle">
          <span></span>
          <h3>{{ sole }}</h3>
        </div>

        <!-- 列表 -->
        <van-grid
          :column-num="3"
          v-for="(item1, index) in channelList"
          :key="index"
          v-show="item1.name == sole"
        >
          <!--   <van-grid :column-num="3">
            <van-grid-item
              v-for="item2 in item1.subCategoryList"
              :key="item2.id"
              :icon="item2.wap_banner_url"
              :text="item2.name"
            />
          </van-grid> -->

          <van-grid-item
            :text="item2.name"
            v-for="item2 in item1.subCategoryList"
            :key="item2.id"
            :icon="item2.wap_banner_url"
          />

          <br />
        </van-grid>
      </ul>
    </div>
  </div>
</template>

<script>
import Popup from "../tsd/Popup.vue";
import { mapGetters } from "vuex";

export default {
  components: {
    Popup,
  },
  name: "category",
  data() {
    return {
      value: "",
      activeKey: 0,
      sole: "",
    };
  },
  methods: {
    fenlFn(name) {
      this.channelList.forEach((item) => {
        if (item.name == name) {
          this.sole = name;
        }
      });
    },
    showPopup() {
      this.show = true;
    },
  },
  mounted() {
    this.$store.dispatch("getHomeDB");
  },
  computed: {
    ...mapGetters(["categoryList", "channelList", "currentCategory"]),
  },
};
</script>

<style lang = "less" scoped>
.slide-enter,
.slide-leave-to {
  right: -100%;
}
.slide-enter-active,
.slide-leave-active {
  transition: right 0.5s linear;
}
.slide-enter-to,
.slide-leave {
  right: 0;
}
/* 分类 */
.fenl {
  width: 100%;
  background-color: #fff;
  height: 90vh;
  display: flex;
  .van-sidebar {
    width: 20%;
    background-color: #f7f8fa;
  }
  ul {
    width: 80%;
    div {
      width: 100%;
      position: relative;
      img {
        margin: 0 7px;
        border-radius: 5px;
        box-shadow: 0 0 6px #000;
        filter: brightness(0.6);
      }
      h5 {
        font-weight: normal;
        width: 100%;
        color: #fff;
        position: absolute;
        top: 48%;
        left: 0%;
        z-index: 222;
        text-align: center;
      }
    }
    .mytitle {
      width: 100%;
      height: 50px;
      position: relative;
      background: #fff;
      font-size: 16px;
      span {
        width: 50%;
        height: 2px;
        background-color: #ccc;
        position: absolute;
        margin: auto;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
      }
      h3 {
        font-weight: normal;
        width: 30%;
        height: 40px;
        background-color: #fff;
        position: absolute;
        margin: auto;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        line-height: 40px;
        text-align: center;
        color: #000;
      }
    }
  }
}
</style>